package com.net.xpay.common.manager.impl;

import com.google.common.base.Preconditions;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.DailyTaskRecordMapper;
import com.net.xpay.common.domain.DailyTaskRecord;
import com.net.xpay.common.enums.systemTask.DailyTaskStatus;
import com.net.xpay.common.manager.DailyTaskRecordManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;


@Component
@ReadTransactional
public class DailyTaskRecordManagerImpl extends AbstractManager<DailyTaskRecord> implements DailyTaskRecordManager{

    @Autowired
    private DailyTaskRecordMapper mapper;


    @Override
    protected BasicMapper<Long, DailyTaskRecord> getMapper() {
        return mapper;
    }

    @Override
    public List<DailyTaskRecord> listManualWaitTask(String taskName) {
        Preconditions.checkNotNull(taskName);
        return nonEmptyList(mapper.selectManualWaitTask(taskName));
    }

    @Override
    public DailyTaskRecord getLatestSuccessTask(String taskName) {
        Preconditions.checkNotNull(taskName);
        return mapper.selectLatestSuccessTask(taskName);
    }

    @Override
    public List<DailyTaskRecord> getUnFinishedTask(String taskName, LocalDate day) {
        Preconditions.checkArgument(taskName != null && day != null);
        DailyTaskRecord condition = new DailyTaskRecord();
        condition.setTaskName(taskName);
        condition.setDay(day);
        condition.setTaskStatus(DailyTaskStatus.START);

        return listByCondition(condition, new ArrayList<>());
    }
}
